# initialize variables
TOP_LEVEL_NAME="npu_tb"

QUARTUS_INSTALL_DIR=$QUARTUS_ROOTDIR

# ----------------------------------------
# overwrite variables - DO NOT MODIFY!
# This block evaluates each command line argument, typically used for 
# overwriting variables. An example usage:
#   sh <simulator>_setup.sh SKIP_SIM=1
for expression in "$@"; do
  eval $expression
  if [ $? -ne 0 ]; then
    echo "Error: This command line argument, \"$expression\", is/has an invalid expression." >&2
    exit $?
  fi
done

#-------------------------------------------
# check tclsh version no earlier than 8.5 
version=$(echo "puts [package vcompare [info tclversion] 8.5]; exit" | tclsh)
if [ $version -eq -1 ]; then 
  echo "Error: Minimum required tcl package version is 8.5." >&2 
  exit 1 
fi 

design_files="*.sv *.v"

vlib altera
vdel -lib altera -all
vlib work
vdel -lib work -all

vlib altera
vlog -work altera \
     $QUARTUS_INSTALL_DIR/eda/sim_lib/altera_primitives.v \
     $QUARTUS_INSTALL_DIR/eda/sim_lib/220model.v \
     $QUARTUS_INSTALL_DIR/eda/sim_lib/sgate.v \
     $QUARTUS_INSTALL_DIR/eda/sim_lib/altera_mf.v \
     $QUARTUS_INSTALL_DIR/eda/sim_lib/fourteennm_atoms.sv

vlib work
vlog -work work $design_files +initreg+0
vsim $TOP_LEVEL_NAME \
     -c \
     -L altera \
     -t ps \
     -do run_all.do

#$QUARTUS_INSTALL_DIR/eda/sim_lib/altera_lnsim.sv \
#$QUARTUS_INSTALL_DIR/eda/sim_lib/ct1_hssi_atoms.sv \
#$QUARTUS_INSTALL_DIR/eda/sim_lib/synopsys/ct1_hssi_atoms_ncrypt.sv \
#$QUARTUS_INSTALL_DIR/eda/sim_lib/synopsys/cr3v0_serdes_models_ncrypt.sv \
#$QUARTUS_INSTALL_DIR/eda/sim_lib/ct1_hip_atoms.sv \
#$QUARTUS_INSTALL_DIR/eda/sim_lib/synopsys/ct1_hip_atoms_ncrypt.sv \
